package com.lwq.project.redis;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.lwq.project.utils.SerializeUtil.SerializeUtil;

import redis.clients.jedis.ShardedJedis;
import redis.clients.jedis.ShardedJedisPool;

/**
* @author 作者 linweiqiang
* @version 创建时间：2017年10月13日 下午2:41:20
* 类说明
*/
@Service
public class RedisDaoImpl implements RedisDao{

	@Autowired
	private  ShardedJedisPool shardedJedisPool;

	public void set(String key, Object value) {
		 ShardedJedis jedis =  shardedJedisPool.getResource();    
		 jedis.set(SerializeUtil.serialize(key), SerializeUtil.serialize(value));
	}

	public void del(String key) {
		ShardedJedis jedis =  shardedJedisPool.getResource();    
		jedis.del(SerializeUtil.serialize(key));
		
	}

	public Object get(String key) {
		ShardedJedis jedis =  shardedJedisPool.getResource();    
		byte[] result = null;
		result = jedis.get(SerializeUtil.serialize(key));
		return SerializeUtil.unserialize(result);
	}    
	
	
}
